package br.edu.unifei.mestrado.commons.partition;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import br.edu.unifei.mestrado.commons.graph.NodeWrapper;

/**
 * Armazena os nós internos de um set. <br>
 * Armazena os nós da fronteira que estão ligados ao nós internos desse set. <br>
 * 
 * @author roberto
 * 
 */
public class NodeCache {

	private int id;

	/**
	 * id_vertice | vertice
	 * 
	 * Lista de nodes que já entraram no set
	 */
	private Map<Long, NodeWrapper> mapNodes = new HashMap<Long, NodeWrapper>();

	public NodeCache(int id) {
		this.id = id;
	}

	public int getId() {
		return id;
	}

	public void addNode(NodeWrapper node) {
		mapNodes.put(node.getId(), node);
	}

	public Collection<NodeWrapper> getNodes() {
		return mapNodes.values();
	}

	public int getSizeNodes() {
		return mapNodes.size();
	}

	public NodeWrapper getVertexById(long id) {
		return mapNodes.get(id);
	}

	public void removeNode(NodeWrapper node) {
		mapNodes.remove(node.getId());
	}

	public boolean isEmpty() {
		return mapNodes.isEmpty();
	}

	public boolean containsNode(long idNode) {
		return mapNodes.containsKey(idNode);
	}
	
	@Override
	public String toString() {
		return "SET_" + id + " N: " + mapNodes.size();
	}

}
